
class HerosUI extends eui.Component
{
	public constructor() 
	{
		super();
		this.addEventListener(eui.UIEvent.COMPLETE, this.uiCompHandler, this);
		//this.skinName = "resource/custom_skins/herosUISkin.exml";
		this.skinName = herosUISkin
	}

	private uiCompHandler(event : eui.UIEvent) : void
	{
		console.log("\t\tHerosUI uiCompHandler");

		///返回逻辑
		this.btnReturn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTouchReturn, this);

		///确定逻辑
		this.btnOK.addEventListener( egret.TouchEvent.TOUCH_TAP, this.onTouchOK, this);

		//填充数据
		this.fillData();

	}

	private onTouchReturn(event : egret.TouchEvent) : void
	{
		this.dispatchEventWith( GameEvents.EVT_RETURN );
	}

	private onTouchOK() : void
	{
		var dp : eui.ICollection = this.listHeros.dataProvider;
		var aNameChecked : string[] = new Array<string>();

		for ( var i : number = 0; i < dp.length; ++i)
		{
			if ( dp.getItemAt( i ).checked )
			{
				aNameChecked.push( dp.getItemAt( i ).heroName );
			}
		}

		if ( aNameChecked.length > 0 )
		{
			Toast.launch( "您选择了：" + aNameChecked.join( ", " ) );
		}
		else
		{
			Toast.launch( "你牛叉，一个也不选！" );
		}
		this.dispatchEventWith(GameEvents.EVT_RETURN);
	}

	private fillData() : void
	{
		var dsListHeros : Array<Object> = 
		[
			{ icon : "heros01_png", heroName : "依文洁琳", comment : "评价：樱桃小丸子", checked : true},
			{ icon : "heros02_png", heroName : "亚特伍德", comment : "评价：离了我你不行的", checked : false},
			{ icon : "heros03_png", heroName : "易妮德", comment : "评价：猴子请来的都比", checked : false},
			{ icon : "heros04_png", heroName : "卢斌", comment : "评价：我勒个去", checked : false},
			{ icon : "heros05_png", heroName : "为弗雷德", comment : "评价：这货碉堡了", checked : false},
			{ icon : "heros06_png", heroName : "斯蒂文", comment : "评价：咖啡不加糖", checked : false},
			{ icon : "heros07_png", heroName : "哈瑞斯", comment : "评价：猪一样的队友", checked : false}
		];

		this.listHeros.dataProvider = new eui.ArrayCollection( dsListHeros );
		this.listHeros.itemRenderer = HerosListIRSkin;
	}

	protected createChildren() : void
	{
		super.createChildren();
	}
	

	private btnReturn : eui.Button;
	private btnOK : eui.Button;
	private listHeros : eui.List;
	private scrListHeros : eui.Scroller;
}

class HerosListIRSkin extends eui.ItemRenderer
{
	private cb : eui.CheckBox;

	constructor()
	{
		super();
		this.skinName = herosListIRSkin;
	}

	protected createChildren() : void 
	{
		super.createChildren();
		this.cb.addEventListener(egret.Event.CHANGE, ()=>
		{
			console.log("\tCheckbox changed:", this.data.checked );
			this.data.checked = this.cb.selected;
		}, this);
	}

}